package com.newegg.app.qec.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.newegg.app.qec.R;
import com.newegg.app.qec.activity.EditorActivity;

import java.util.ArrayList;

/**
 * Created by Allen on 2017/12/13.
 */
public class AddressAdapter extends BaseAdapter implements View.OnClickListener {
    private Context context;
    private LayoutInflater inflater;
    private ArrayList<String> list = new ArrayList<>();

    public AddressAdapter(Context context, ArrayList<String> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.address_listview_item, null);
            holder.linear_editor = (LinearLayout) convertView.findViewById(R.id.editor_linear);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.linear_editor.setOnClickListener(this);
        return convertView;
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.editor_linear:
                intent.setClass(context, EditorActivity.class);
                context.startActivity(intent);
                break;
        }
    }

    class ViewHolder {
        LinearLayout linear_editor;
    }
}
